﻿using System.ComponentModel;
using System;

namespace Esponce.QRCode.Models
{
	public class DeviceRecord : IRecord, INotifyPropertyChanged
	{
		#region Public properties
		/// <summary>
		/// Gets or sets number of records in the group.
		/// </summary>
		public int Count
		{
			get
			{
				return this.count;
			}
			set
			{
				if (this.count != value)
				{
					this.count = value;
					OnPropertyChanged("Count");
				}
			}
		}
		private int count;

		/// <summary>
		/// Gets or sets either device name (manufacturer + model) or device platform. Returns "N/A" on unknown device/platform.
		/// </summary>
		public string Name
		{
			get
			{
				if (!string.IsNullOrEmpty(this.Manufacturer))
				{
					return (this.Manufacturer + " " + this.ModelName).Trim();
				}
				else
				{
					return this.Platform ?? "N/A";
				}
			}
			set
			{
				//Not handled here but required by IRecord
			}
		}

		/// <summary>
		/// Gets or sets device manufacturer, e.g. Samsung, Apple, Nokia
		/// </summary>
		public string Manufacturer
		{
			get
			{
				return this.manufacturer;
			}
			set
			{
				if (this.manufacturer != value)
				{
					this.manufacturer = value;
					OnPropertyChanged("Manufacturer");
				}
			}
		}
		private string manufacturer;

		/// <summary>
		/// Gets or sets device model name, e.g. iPhone, Lumia 800
		/// </summary>
		public string ModelName
		{
			get
			{
				return this.modelName;
			}
			set
			{
				if (this.modelName != value)
				{
					this.modelName = value;
					OnPropertyChanged("ModelName");
				}
			}
		}
		private string modelName;

		/// <summary>
		/// Gets or sets platform name, e.g. iOS, Android, Windows Phone
		/// </summary>
		public string Platform
		{
			get
			{
				return this.platform;
			}
			set
			{
				if (this.platform != value)
				{
					this.platform = value;
					OnPropertyChanged("Platform");
					OnPropertyChanged("Name");
				}
			}
		}
		private string platform;
		#endregion

		#region INotifyPropertyChanged Members
		public event PropertyChangedEventHandler PropertyChanged;
		protected virtual void OnPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}
		#endregion
	}
}
